/*
 * @Author: Kevin Zhao
 * @Date: 2021-04-24 21:53:20
 * @LastEditTime: 2021-12-11 18:50:38
 * @LastEditors: Kevin Zhao
 * @Description: 登录注册api
 * @FilePath: \uniapp-pro\src\api\login.ts
 */
import request from '../server/request'
import { sessionIdInterface } from './config/interface'

interface codeInterface {
    code: number | string // 从wx.login获取到的code
}

interface openIdInterface {
    openId: number | string // openId
}

interface phoneInterface {
    phoneNumber: number | string // 手机号
}

interface authCodeInterface extends phoneInterface{
    authCode: number | string // 授权码
}

interface verifyCodeInterface extends phoneInterface{
    verifyCode: number | string // 验证码
}

interface userPasswordInterface extends phoneInterface{
    userPassword: number | string // 密码
}

interface registerInterface {
    name: string,  // 用户姓名
    idNo?: number | string, // idNo
    phoneNumber: number | string, // 手机号 
    address?: string, // 地址
    userPassword: string, // 密码
    verifyCode: string, // 验证码
    portraitUri?: string, // 用户头像
    openId: string, // openId
}

interface resetPwdInterface {
    idNo: string, // idNo
    verifyCode: string, // 验证码
    newPassword: string // 新密码
}

interface modifyPhoneInterface extends sessionIdInterface{
    phone: string, // 手机号
    newPhone: string, // 新手机号
    verifyCode: string, // 验证码
}

/**
 * @description: 登录
 * @param {codeInterface} params
 * @return {*}
 */
export const getOpenIdAPI = (params: codeInterface):any => {
    return request(params,'getOpenId')
}

/**
 * @description: 获取短信发送授权码
 * @param {phoneInterface} params
 * @return {*}
 */
export const getVerifyAuthCodeAPI = (params: phoneInterface):any => {
    return request(params,'getVerifyAuthCode')
}

/**
 * @description: 根据授权码发送短信
 * @param {authCodeInterface} params
 * @return {*}
 */
export const sendVerifyByAuthCodeAPI = (params: authCodeInterface):any => {
    return request(params,'sendVerifyByAuthCode')
}

/**
 * @description: 验证手机号码是否注册
 * @param {verifyCodeInterface} params
 * @return {*}
 */
export const checkPhoneRegAPI = (params: verifyCodeInterface):any => {
    return request(params,'checkPhoneReg')
}

/**
 * @description: 用户登陆（密码）
 * @param {userPasswordInterface} params
 * @return {*}
 */
export const loginAPI = (params: userPasswordInterface):any => {
    return request(params,'login')
}

/**
 * @description: 用户登陆（验证码）
 * @param {verifyCodeInterface} params
 * @return {*}
 */
export const loginByVerifyCodeAPI = (params: verifyCodeInterface):any => {
    return request(params,'loginByVerifyCode')
}

/**
 * @description: 用户登陆（openId）
 * @param {openIdInterface} params
 * @return {*}
 */
export const loginByOpenIdAPI = (params: openIdInterface):any => {
    return request(params,'loginByOpenId')
}

/**
 * @description: 注册
 * @param {registerInterface} params
 * @return {*}
 */
export const userRegisterAPI = (params: registerInterface):any => {
    return request(params,'userRegister')
}

/** 
 * @description: 修改密码
 * @param {resetPwdInterface} params
 * @return {*}
 */
export const resetPwdAPI = (params: resetPwdInterface):any => {
    return request(params,'resetPwd')
}

/** 
 * @description: 修改手机号
 * @param {modifyPhoneInterface} params
 * @return {*}
 */
export const modifyPhoneAPI = (params: modifyPhoneInterface):any => {
    return request(params,'modifyPhone')
}
